package com.inwavetech.os.util.field.dynamicfields;

import android.view.ViewGroup;

import com.inwavetech.os.util.field.FieldsCollection;


/**
 * Created by jgskin on 2/14/14.
 */
public class DynamicFields extends EntityUpdatableFields {

    protected final ViewGroup container;
    protected final ViewGroup box;

    public DynamicFields(Object entity, FieldsCollection fields, ViewGroup container, ViewGroup box) {
        super(entity, fields);
        this.container = container;
        this.box = box;
    }

    public final void attach() throws NoSuchFieldException, IllegalAccessException {
        clearContainer();

        updateFields();

        container.addView(box);
    }

    public boolean isValid() {
        return fields.isValid();
    }

    public void clearContainer() {
        container.removeAllViews();
    }

}
